const db = wx.cloud.database();
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
     display: "block",
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 100,
    current:0,
    imageList:[
        {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/lbtwo.png"},
       {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/lbone.png"},
       {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/lbthree.png"}
    ],
        page: 38,  
        xiangmu:0,
        xiangmus:['国家公务员','山东公务员'],    
        year: 0,
        years: ['2018', '2019', '2020', '2021'],
        diqu: 0,
        diqus: ['滨州','聊城','济宁','淄博','泰安','烟台','东营','省属','青岛','临沂','济南','潍坊','德州','日照','菏泽','威海','枣庄'],
    },
    yearsChange: function (e) {
        console.log('years发送选择改变，携带值为', e.detail.value)
        this.setData({
            year: e.detail.value
        })
    },
    diqusChange: function (e) {
        console.log('diqus发送选择改变，携带值为', e.detail.value)
        this.setData({
            diqu: e.detail.value
        })
    },
    xiangmusChange: function (e) {
        console.log('xiangmus发送选择改变，携带值为', e.detail.value)
        this.setData({
            xiangmu: e.detail.value
        })
    },

    swipclick: function (e) {//点击图片触发事件
        console.log(this.data.imageList[this.data.current]);
        wx.navigateTo({
            url: '../tiaozhuan/tiaozhuan',
          })
    },
    bindchange:function(e){//轮播图发生改变
        this.setData({
            current:e.detail.current
        })
    },
    onLoad: function (options) {

        var that = this;
        console.log(options)
        that.setData({
            area: options.area,
            geneal: options.agent
        })
        if (options.page) {
            that.setData({
                page: options.page
            })
        }
    },
    goToGK(){
        wx.navigateToMiniProgram({
            appId: 'wx8edbb3c4c705a97b',//国考appid
            path: '',
            envVersion: 'release',// 打开正式版
            success(res) {
                console.log(res)
            },
           fail: function (err) {
              console.log(err);
           }
        })
    },
    goToSK(){
        wx.navigateToMiniProgram({
            appId: 'wx3d539ffbe6c9073b',//省考appid
            path: '',
            envVersion: 'release',// 打开正式版
            success(res) {
                console.log(res)
            },
           fail: function (err) {
              console.log(err);
           }
        })
    },
    // hideview: function() {
    //     var shoujihao=wx.getStorageSync('phone')
    //     console.log(shoujihao)
    //     if(shoujihao!=''){
    //         this.setData({
    //             display: "none"
    //           })
    //     }
        
    //   },
      goTo(){
          var that=this;
        console.log(that.data.xiangmus[that.data.xiangmu])
        if(that.data.xiangmus[that.data.xiangmu]=='国家公务员'){
            wx.navigateToMiniProgram({
                appId: 'wx3bfce5135e23ad3f',//国考appid
                path: '',
                envVersion: 'release',// 打开正式版
                success(res) {
                    console.log(res)
                },
               fail: function (err) {
                  console.log(err);
               }
            })
        }
        else{
            wx.navigateToMiniProgram({
                appId: 'wx2509acc672d530e5',//省考appid
                path: '',
                envVersion: 'release',// 打开正式版
                success(res) {
                    console.log(res)
                },
               fail: function (err) {
                  console.log(err);
               }
            })
        }
      },
    getPhoneNumber(e) {
        var that = this;
            wx.cloud.callFunction({
                name: 'getMobile',
                data: {
                    weRunData: wx.cloud.CloudID(e.detail.cloudID),
                }
            }).then(res => {
                that.setData({
                    mobile: res.result,
                })
                wx.setStorageSync('phone', res.result)
                console.log(res.result)
                wx.request({ //发送请求
                    url: "https://zg99.offcn.com/index/biaodan/register/?actid=41387&callback=?",
                    data: {
                        name: that.data.inputValue,
                        xueli: that.data.xueLi,
                        yuanxiao:that.data.inputValueT,
                        phone: res.result,
                        fenxiao: that.data.area,
                        geneal: that.data.geneal
                    }, //接收参数
                    success(res) { //返回
                        var jsonStr = res.data;
                        jsonStr = jsonStr.replace("(", "");
                        jsonStr = jsonStr.replace(")", "");
                        if (typeof jsonStr != 'object') {
                            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                            var theJson = JSON.parse(jsonStr);
                        };
                        console.log(theJson)
                        that.setData({
                            display: "none"
                          })          
    
                    }
                })
    
                wx.request({
                    url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/wx_collect_info',
                    method: 'POST',
                    data: {
                        activity_id: 30,
                        mobile: res.result,
                        area_code: that.data.area,
                        agent: that.data.geneal,
                        extra: {
                            dishi: that.data.dishi,
                            zkz: that.data.zkz,
                        },
                        page_index: that.data.page
                    },
                    success: res => {
                        console.log(res);
                    }
                })
    
            }).catch(err => {
                console.error(err);
            });
    },
    info(e) {
        wx.request({ //发送请求
            url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=35888&callback=?",
            data: {
                province: '山东省',
                city:'',
                limits:'500'
              
            }, //接收参数
            success(res) { //返回
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                };
                console.log(theJson)

            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})